<template>
  <div class="tenantMenu_main main_container">
    <div v-loading="loading" class="main_main">
      <div style="margin-bottom:20px" class="SearchBar_main main_main_search">
        <div class="main_main_search_item">
          <!-- <a class="button" @click="add">
              新增
            </a> -->
        </div>
        <div class="main_main_search_item">
          <el-input v-model="pageData.searchValue" class="search_input" placeholder="请输入订单号或销售人员" clearable @keyup.enter.native="()=>{pageData.pageNum=1; getList()}" @clear="getList" />
          <el-button class="button_icon" icon="el-icon-search" @click.stop="()=>{pageData.pageNum=1; getList()}" />
        </div>
      </div>
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          :row-class-name="tableRowClass"
          :height="tableHeight"

          stripe
          border
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          @row-click="chooseOrder"
        >
          <Column v-for="(column,index) in defaultTableColumns" :key="index" :prop="column.prop" :align="column.align" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" :min-width="column.minWidth" />
          <el-table-column
            label="附件"
            min-width="80"
          >
            <template slot-scope="scope">
              <FileManage
                :file-names="scope.row.fileName"
                :file-real-names="scope.row.fileRealName"
                :file-urls="scope.row.url"
                :readonly="true"
                class="accessory"
              />
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="main_bottom">
      <pagination
        :total="total"
        :page.sync="pageData.pageNum"
        :limit.sync="pageData.pageSize"
        :selected-num="selectionsAll.length"
        @pagination="getList"
      />
    </div>

  </div>
</template>

<script>
import { listForReturn } from '@/api/receivableAndPayable/receivableAndPayableManage/additionalReceipt'
export default {
  props: {
    layerid: {},
    id: {},
    selectionId: {}
  },
  data() {
    return {
      templateSelection: '',
      loading: false,
      pageData: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc',
        // isReturn: '0',
        status: '4,5,6,7',
        searchValue: ''
      },
      // tableKey: 1,
      total: 1, // 数据一共有多少条
      mainId: 'id', // 表格行ID
      tableHeight: '300', // 表格高度
      tableData: [], // 表格数据
      tableColumns: [], // 表格实际用的字段
      searchColumns: [], // 搜索区实际用的字段
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'code', label: '销售订单号', minWidth: '120' },
        { prop: 'orderName', label: '销售人员', minWidth: '100' },
        { prop: 'customerName', label: '客户名称', minWidth: '100' },
        { prop: 'orderGoodsTime', label: '订货日期', minWidth: '140' },
        { prop: 'contractCode', label: '合同号', minWidth: '100' },
        { prop: 'hasPrice', label: '已收款金额', minWidth: '100' },
        { prop: 'unPrice', label: '未收款金额', minWidth: '100' },
        { prop: 'orderNumber', label: '订单数量', minWidth: '100' },
        { prop: 'taxAllPrice', label: '含税总金额', minWidth: this.SETTINGS.settings_decimalDigits_length, align: 'right' },
        { prop: 'tax', label: '税额', minWidth: this.SETTINGS.settings_decimalDigits_length, align: 'right' },
        { prop: 'remark', label: '备注', minWidth: '200' }
      ]
    }
  },
  created() {
  },
  mounted() {
    this.getList()
    if (this.selectionId) {
      this.templateSelection = this.selectionId
    }
  },
  methods: {
    tableRowClass({ row }) {
      if (row.id == this.templateSelection) {
        return 'rowSelected'
      } else {
        return ''
      }
    },
    getList() {
      listForReturn({ ...this.pageData, isReturn: '0' }).then(res => {
        this.tableData = res.data
        this.total = res.total
        this.loading = false
        this.$nextTick(() => {
          this.setSelectRow(this)// 设置行选中
          this.tableHeight = this.$refs.table_container.offsetHeight
        })
      })
    },
    chooseOrder(row) {
      this.$parent.showOrder(row)
      this.$layer.close(this.layerid)
      // if (row.isReturn == 1) {
      //   this.$message.warning('该销售订单存在未入库的退货单')
      // } else if (row.isReturn == 2) {
      //   this.$message.warning('该销售订单存在未检验的退货单')
      // } else {
      //   this.$parent.showOrder(row)
      //   this.$layer.close(this.layerid)
      // }
    }
  }
}
</script>

<style lang="less" scoped>
.button{
  width: 100px;
  height: 30px;
  color: #fff;
  background-color: #387bfc;
  border-radius: 4px;
  text-align: center;
  line-height: 30px;
}
.main_search_item{
  padding-right: 20px !important;
}
.main_main_search{
  padding-right: 20px !important;
}
.main_main_search_item{
  padding-left: 20px !important;
}
.main_main{
  margin:0 !important;
  padding-top:0 !important;
  height: calc(100% - 50px) !important;
}
.button_icon{
  background:#387bfc;
  width:30px;
}
.search_input{
  width:200px;
  margin-right:10px
}
.table_container{
  margin: 0 !important;
}
/deep/ .el-input--suffix .el-input__inner {
  padding-right:25px;
}
/deep/ .el-table--enable-row-hover .el-table__body tr:hover > td {
  background-color: rgba(56, 123, 252, 0.5) !important;
  color: #ffffff;
}
</style>
